<!doctype html>
<html>
<head>
	<meta charset="UTF-8"/>
	<title>争议数据列表</title>
	<link rel="stylesheet" type="text/css" href="/webapp/css/easyui.css">
	<link rel="stylesheet" type="text/css" href="/webapp/css/icon.css">
	<link rel="stylesheet" type="text/css" href="/webapp/css/color.css">
	<link rel="stylesheet" type="text/css" href="/webapp/css/public.css">
	<script type="text/javascript" src="/webapp/js/lib/jquery.min.js"></script>
	<script type="text/javascript" src="/webapp/js/lib/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="/webapp/js/lib/jquery.global.settings.js"></script>
	<script type="text/javascript" src="/webapp/js/lib/ajaxfileupload.js"></script>
	<script type="text/javascript" src="/webapp/js/common/config.js"></script>
</head>
<body>
<div class="easyui-container-fluid">
	<div class="easyui-panel" style="border: none;">
		<div class="nav" id="nav"></div>
		<div class="easyui-panel" style="border:none;">
			<form id="ff">
				<div style="margin-bottom:20px">

					<label class="item-label">年：</label>
					<input type="text" id="year" name="year" class="easyui-combobox" style="width: 100px;" >
					<span id="monthLabel">
						<label class="item-label">月：</label>
						<input type="text" id="month" name="month" class="easyui-combobox" style="width: 100px;" >
					</span>
					<span id="weekLabel">
						<label class="item-label">周：</label>
						<input type="text" id="week" name="week" class="easyui-combobox" style="width: 100px;" >
					</span>
					<label class="item-label">争议类型：</label>
					<select name="disputeType" class="easyui-combobox" data-options="panelHeight:'auto'" style="width: 100px;" >
						 <option value="1">品类争议</option>
						 <option value="2">商场争议</option>
						 <option value="3">品牌争议</option>
						 <option value="4">型号争议</option>
					</select>
					<label class="item-label">禁用类型：</label>
					<select id="disableType" name="disableType" class="easyui-combobox"  style="width: 120px;">
						<option value="">请选择</option>
						<option value="D0">争议禁用</option>
						<option value="D1">SKU禁用</option>
						<option value="D2">全品类禁用字</option>
						<option value="D3">未识别品类</option>
						<option value="D4">品类禁用字</option>
						<option value="D5">禁用代换库</option>
						<option value="D6">手动禁用</option>
						<option value="D7">电商历史争议</option>
						<option value="D8">渠道手工禁用</option>
						<option value="D9">品类合并禁用</option>
						<option value="SALESPRICE">销价异常</option>
						<option value="SALESCOUNT">销量异常</option>
						<option value="OBLITERATE">退货核销</option>
					</select>
					<label class="item-label">商场码：</label>
					<input type="text" id="mallCode" name="mallCode" class="easyui-textbox" style="width: 100px;" >

					<label class="item-label">原始品类：</label>
					<input type="text" id="originalCategory" name="originalCategory" class="easyui-textbox" style="width: 100px;" >
					<label class="item-label">原始品牌：</label>
					<input type="text" id="originalBrand" name="originalBrand" class="easyui-textbox" style="width: 100px;" >
					<label class="item-label">原始型号：</label>
					<input type="text" id="originalModel" name="originalModel"  class="easyui-textbox" style="width: 100px;" >
				</div>
				<div style="margin-bottom:20px;">
					<label class="item-label">品类：</label>
					<input type="text" id="categorySelect" name="categoryCode" class="easyui-combobox" data-options="panelHeight:'150'" style="width:100px;"/>
					<label class="item-label">渠道码：</label>
					<select id="channelComparer" name="channelComparer" class="easyui-combobox" data-options="panelHeight:'auto'" style="width:53px;">
						<option value="EQUAL"  selected = "selected" >=</option>
						<option value="NOT_EQUAL"><pre><></pre></option>
					</select>
					<input id="channel" name="channelCode" class="easyui-textbox" style="width: 100px;"/>
					<label class="item-label">筛选条件：</label>
					<select id="columnbox" name="column" class="easyui-combobox" data-options="panelHeight:'auto'" style="width:5%;">
						<option value="">-请选择-</option>
						<option value="PRICE">价格</option>
						<option value="COUNT">销量</option>
						<option value="ORIGINAL_PRICE">原价</option>
						<option value="ORIGINAL_COUNT">原量</option>
					</select>
					<select id="comparerbox" name="comparer" class="easyui-combobox" data-options="panelHeight:'auto'" style="width:6%;" prompt="比较符">
						<option value=""></option>
						<option value="EQUAL">=</option>
						<option value="GREAT_EQUAL">&gt;=</option>
						<option value="GREAT">&gt;</option>
						<option value="LITTLE">&lt;</option>
						<option value="LITTLE_EQUAL">&lt;=</option>
					</select>
					<input type="text" id="valuebox" name="value" class="easyui-textbox" prompt="数值" data-options="" style="width:4%;"/>
					<label class="item-label">量|价|额：</label>
					<input id="dataTotal" class="easyui-switchbutton" style="width:92px;height:30px;" >
					<label class="item-label">状态：</label>
					<input id="entityStatus" class="easyui-switchbutton" checked style="width:100px;height:30px;" onText="启用" offText="禁用"  >

					<a href="javascript:void(0);" class="easyui-linkbutton c8" style="margin-left:40px;width:80px;" onclick="searchBy()">查询</a>
					<a href="javascript:void(0);" class="easyui-linkbutton c6" style="margin-left:40px;width:80px;" onclick="syncDisputeSku()">同步sku</a>
				</div>
			</form>
		</div>
		<div class="table-wrapper">
			<div id="th">
				<div>
					<a href="#" onclick="disable()" class="easyui-linkbutton" iconCls="icon-no" plain="true">禁用</a>
					<a href="#" onclick="ok()" class="easyui-linkbutton" iconCls="icon-ok" plain="true">启用</a>
					&nbsp;&nbsp;&nbsp;
					||&nbsp;&nbsp;
					<span>品牌转移到:</span>
					<input class="easyui-combobox" id="brandList" style="width: 100px"/>
					<a href="#" onclick="moveBrand()" class="easyui-linkbutton"  plain="true">转移</a>&nbsp;&nbsp;&nbsp;||&nbsp;&nbsp;
					<span>品类转移到:</span>
					<input class="easyui-combobox" id="categoryList" style="width: 100px"/>
					<a href="#" onclick="moveCategory()" class="easyui-linkbutton"  plain="true">转移</a>&nbsp;&nbsp;
					<a href="#" onclick="copyCategory()" class="easyui-linkbutton"  plain="true">复制</a>&nbsp;&nbsp;&nbsp;||&nbsp;&nbsp;
					<span>型号转移到:</span>
					<input class="easyui-combobox" id="modelList" prompt="请输入要转移的型号", style="width: 300px"/>
					<a href="#" onclick="moveModel()" class="easyui-linkbutton"  plain="true">转移</a>&nbsp;&nbsp;
					<input type="button" class="easyui-linkbutton" value="追加禁用库" onclick="addDisableMatch()" style="height: 32px;width:80px;"/>
				</div>
			</div>
			<table id="datagrid" style="width: auto" data-options="fitColumns:true,scrollbarSize:0,striped:true">
				<thead>
				<tr>
					<th field="ck" checkbox="true"></th>
					<th data-options="field:'channelCode',align:'center'" width="40px">渠道码 </th>
					<th data-options="field:'mallCode',align:'center'" width="50px">商场码</th>
					<th data-options="field:'brandName',align:'center'" width="50">品牌</th>
					<th data-options="field:'middleBrandNames',align:'center'" width="50">中间品牌</th>
					<th data-options="field:'originalBrand',align:'center'" width="100">原始品牌</th>
					<th data-options="field:'categoryName',align:'center'" width="80">品类|禁用字</th>
					<!--<th data-options="field:'middleCategoryNames',align:'center'" width="50">中间品类</th>-->
					<th data-options="field:'originalCategory',align:'center'" width="150">原始品类</th>
					<th data-options="field:'originalModel',align:'center'" width="150">原始型号</th>
					<th data-options="field:'price',align:'center',formatter:priceFormatter" width="50">现/原销价</th>
					<th data-options="field:'count',align:'center',formatter:countFormatter" width="50">现/原销量</th>
					<th data-options="field:'total',align:'center',formatter:totalFormatter" width="50">现/原销额</th>
					<th data-options="field:'disabledType',align:'center',formatter:disabledTypeFormatter" width="50">禁用原因</th>
					<th data-options="field:'entityStatus',align:'center',formatter:statusFormatter" width="30">状态</th>
					<th data-options="field:'action',formatter:actions,align:'center'" width="50">操作</th>
				</tr>
				</thead>
				<tbody>
				</tbody>
			</table>
		</div>
	</div>
</div>
</body>
<script type="text/javascript">

	var globalData = [];
    $(function(){
        setNav();
        initBrandSelect("brandList");
        initUserCategorySelect1("categorySelect");
        initCategorySelectnew("categoryList");
        $("#modelList").combobox({
			mode:"remote",
			url:config.url+"/model/findByQ",
            valueField:"code",
            textField:"name",
            method:"get",
            formatter:function (row) {
                var opts = $(this).combobox('options');
                return row.brandName+"|"+row.categoryName+"|"+row.name;
            }
		});
        var height = $(window).height();
        var nav_height = $("#nav")._outerHeight();
        var ff_height = $("#ff").height();
        var table_height = height-nav_height-ff_height-20;
        $("#datagrid").css("max-height",table_height);
        $("#datagrid").datagrid({
            pagination:true,
            rownumbers:true,
            toolbar:"#th",
            onLoadSuccess:function (data) {
                $("#datagrid").datagrid("clearChecked");
                var stats = "<div class='stats'><label>销量 ：{{totalCount}}</label>&nbsp;&nbsp;&nbsp;<label>金额 ：{{totalPrice}}</label>&nbsp;&nbsp;&nbsp;<label>均价 ：{{avgPrice}}</label></div>";
                stats = stats.replace("{{totalCount}}", globalData.map.totalCount ? globalData.map.totalCount : 0);
                stats = stats.replace("{{totalPrice}}",globalData.map.totalPrice? globalData.map.totalPrice : 0);
                stats = stats.replace("{{avgPrice}}",globalData.map.avgPrice? globalData.map.avgPrice : 0);
                $(".datagrid-wrap").find(".stats").remove();
                //before：在div外的后面加入标签
                $(".datagrid-wrap").find(".datagrid-pager").find(".pagination-info").before(stats);

            },
        }).datagrid("getPager").pagination({
			onSelectPage:searchBy
		});
        initMonthWeek("monthLabel", "weekLabel");
        // $.when(initMonthWeek("monthLabel","weekLabel")).done(searchBy);
        aRecords("争议数据","/webapp/pages/channel/salesDetail/dispute")
    });

    function initUserCategorySelect1(selectId){
        var dtd = $.Deferred();
        var data = window.parent.userCategoryManageList.slice();
        if(data){
            data.unshift({"name":"","code":"","selected":true});
            $("#"+selectId).combobox({
                "textField":"name",
                "valueField":"code",
                "panelHeight":150,
                "prompt":"--请选择--",
                "data":data,
            }).combobox("setValue",data[0]);
        }
        dtd.resolve();
        return dtd.promise();
    }

    function disable() {
        var rows = $('#datagrid').datagrid('getSelections');
        if (rows.length == 0) {
            $.messager.alert("提示", "请选择禁用数据");
            return;
        }
        $.messager.confirm("提示", "您确定禁用这些记录吗？", function (flag) {
            if (flag) {
                var ids = [];
                for (var i = 0; i < rows.length; i++) {
                    ids.push(rows[i].id);
                }
                $.ajax({
                    url: config.url + "/sales/detail/disable",
                    type: 'post',
                    data: JSON.stringify(ids),
                    contentType: "application/json",
                    xhrFields: {withCredentials: true},
                    success: function (data) {
                        $.messager.alert("提示", "操作成功", "info", function () {
                            searchBy();
                        });
                    },
                    error: function (XMLHttpRequest, textStatus, thrown) {
                        $.messager.alert("提示", "操作失败", "error");
                    }
                })
            }
        });
    }
    function ok() {
        var rows = $('#datagrid').datagrid('getSelections');
        if (rows.length == 0) {
            $.messager.alert("提示", "请选择启用数据");
            return;
        }
        $.messager.confirm("提示", "您确定启用这些记录吗？", function (flag) {
            if (flag) {
                var ids = [];
                for (var i = 0; i < rows.length; i++) {
                    ids.push(rows[i].id);
                }
                $.ajax({
                    url: config.url + "/sales/detail/enable",
                    type: 'post',
                    data: JSON.stringify(ids),
                    contentType: "application/json",
                    xhrFields: {withCredentials: true},
                    success: function (data) {
                        $.messager.alert("提示", "操作成功", "info", function () {
                            searchBy();
                        });
                    },
                    error: function (XMLHttpRequest, textStatus, thrown) {
                        $.messager.alert("提示", "操作失败", "error");
                    }
                })
            }
        });
    }

    function moveBrand() {
        var rows = $('#datagrid').datagrid('getSelections');
        if (rows.length == 0) {
            $.messager.alert("提示", "请选择要转移的数据");
            return;
        }
        var brandCode=$("#brandList").combobox("getValue");
        console.log(brandCode);
        if (!brandCode){
            $.messager.alert("提示", "请选择要转移的品牌");
            return;
        }
        $.messager.confirm("提示", "您确定移动这些记录吗？", function (flag) {
            if (flag) {
                var ids = [];
                for (var i = 0; i < rows.length; i++) {
                    ids.push(rows[i].id);
                }
                var params = {reportType:window.parent.workMode.toUpperCase(),ids:ids};
                $.ajax({
                    url: config.url + "/sales/detail/brand/moveTo/"+brandCode,
                    type: 'post',
                    data: params,
                    traditional:true,
                    //contentType: "application/json",
                    xhrFields: {withCredentials: true},
                    success: function (data) {
                        $.messager.alert("提示", "操作成功", "info", function () {
                            searchBy();
                        });
                    },
                    error: function (XMLHttpRequest, textStatus, thrown) {
                        $.messager.alert("提示", "操作失败", "error");
                    }
                })
            }
        });
    }
    function moveCategory() {
        var rows = $('#datagrid').datagrid('getSelections');
        if (rows.length == 0) {
            $.messager.alert("提示", "请选择要转移的数据");
            return;
        }
        var categoryCode=$("#categoryList").combobox("getValue");
        if (!categoryCode){
            $.messager.alert("提示", "请选择要转移的品类");
            return;
        }
        $.messager.confirm("提示", "您确定移动这些记录吗？", function (flag) {
            if (flag) {
                var ids = [];
                for (var i = 0; i < rows.length; i++) {
                    ids.push(rows[i].id);
                }
                var params = {reportType:window.parent.workMode.toUpperCase(),ids:ids};
                $.ajax({
                    url: config.url + "/sales/detail/category/moveTo/"+categoryCode,
                    type: 'post',
                    data: params,
                    //contentType: "application/json",
                    traditional:true,
                    xhrFields: {withCredentials: true},
                    beforeSend:function () {
                        $.messager.progress({
                            title:"请稍等",
                            interval:40,
                            text:"数据转移中..."
                        });
                    },
                    complete:function () {
                        $.messager.progress("close");
                    },
                    success: function (data) {
                        $.messager.alert("提示", "操作成功", "info", function () {
                            searchBy();
                        });
                    },
                    error: function (XMLHttpRequest, textStatus, thrown) {
                        $.messager.alert("提示", "操作失败", "error");
                    }
                })
            }
        });
    }
    function copyCategory() {
        var rows = $('#datagrid').datagrid('getSelections');
        if (rows.length == 0) {
            $.messager.alert("提示", "请选择要复制的数据");
            return;
        }
        var categoryCode=$("#categoryList").combobox("getValue");
        if (!categoryCode){
            $.messager.alert("提示", "请选择要复制的品类");
            return;
        }
        $.messager.confirm("提示", "您确定复制这些记录吗？", function (flag) {
            if (flag) {
                var ids = [];
                for (var i = 0; i < rows.length; i++) {
                    ids.push(rows[i].id);
                }
                var params = {ids:ids,reportType:window.parent.workMode.toUpperCase()};
                $.ajax({
                    url: config.url + "/sales/detail/category/copyTo/"+categoryCode,
                    type: 'post',
                    data: params,
                    //contentType: "application/json",
                    traditional:true,
                    xhrFields: {withCredentials: true},
                    success: function (data) {
                        $.messager.alert("提示", "操作成功", "info", function () {
                            searchBy();
                        });
                    },
                    error: function (XMLHttpRequest, textStatus, thrown) {
                        $.messager.alert("提示", "操作失败", "error");
                    }
                })
            }
        });
    }
    function moveModel() {
        var rows = $('#datagrid').datagrid('getSelections');
        if (rows.length == 0) {
            $.messager.alert("提示", "请选择要转移的数据");
            return;
        }
        var categoryCode = $("#modelList").combobox("getValue");
        if (!categoryCode) {
            $.messager.alert("提示", "请选择要转移的型号");
            return;
        }
        $.messager.confirm("提示", "您确定移动这些记录吗？", function (flag) {
            if (flag) {
                var ids = [];
                for (var i = 0; i < rows.length; i++) {
                    ids.push(rows[i].id);
                }
                var params = {ids:ids,reportType:window.parent.workMode.toUpperCase()};
                $.ajax({
                    url: config.url + "/sales/detail/model/moveTo/" + categoryCode,
                    type: 'post',
                    data: params,
                    //contentType: "application/json",
                    traditional:true,
                    xhrFields: {withCredentials: true},
                    success: function (data) {
                        $.messager.alert("提示", "操作成功", "info", function () {
                            searchBy();
                        });
                    },
                    error: function (XMLHttpRequest, textStatus, thrown) {
                        $.messager.alert("提示", "操作失败", "error");
                    }
                })
            }
        });
    }
    function actions(val,row){
        var disableText=row.entityStatus=="OK"?"禁用":"启用";
        var disableStatus=row.entityStatus=="OK"?"DISABLE":"OK";
        return "<a href='javascript:void(0);' class='easyui-linkbutton l-btn l-btn-small' "+
            "style='width:90px;' onclick='disableOne(\""+row.id+"\",\""+disableStatus+"\")'>"+disableText+"</a>&nbsp;&nbsp;"
    }
    function disableOne(id,status){
		var disableText;
		var statusUrl;
		if (status == "OK") {
			disableText = "启用";
			statusUrl = "enable";
		}else{
			disableText = "禁用";
			statusUrl = "disable";
		}
        $.messager.confirm("提示","您确定"+disableText+"该记录吗？",function(flag){
            if(flag){
                $.ajax({
                    url:config.url+"/sales/detail/"+statusUrl,
                    type:'post',
					data:JSON.stringify(Array.of(id)),
					contentType: "application/json",
                    xhrFields:{withCredentials:true},
                    success:function(data){
                        $.messager.alert("提示","操作成功","info",function () {
							searchBy();
                        });
                    },
                    error:function(XMLHttpRequest,textStatus,thrown){
                        $.messager.alert("提示","操作失败","error");
                    }
                });
            }
        });
    }
    function searchBy(page, size){
        var pageParm = {};
        pageParm['page'] = page||1;
        pageParm['size'] = $("#datagrid").datagrid("getPager").pagination("options").pageSize||size;
        var param = getFormData(document.getElementById("ff"));
		param.reportType = window.parent.workMode.toUpperCase();
		param.entityStatus = $("#entityStatus").switchbutton("options").checked==true?"OK":"DISABLE";
        param.dataTotal = $("#dataTotal").switchbutton("options").checked == true ? true : false;
        if (param.column && param.comparer && param.value) {
            param.integerFilters = [{column: param.column, comparer: param.comparer, value: param.value}];
        }

        $.ajax({
            url:config.url + "/sales/detail/dispute?"+transfer2url(pageParm),
            type:"post",
            data:JSON.stringify(transfer(param)),
            contentType:"application/json;charset=UTF-8",
            xhrFields:{withCredentials:true},
			beforeSend:function () {
				$.messager.progress({
					title:"请稍等",
					interval:50,
					text:"数据加载中..."
				});
			},
			complete:function () {
                $.messager.progress("close");
            },
            success:function(data){
                $.messager.progress("close");
                if (data.code == 200) {
                    globalData = data.msg;
                    data.msg.content.forEach(function (sd) {
                        if (sd.entityStatus == "DISABLE" && (sd.disabledType == "D4"||sd.disabledType == "D2")) {
                            sd.categoryName = sd.disableWords;
                        }
                    });
                    $("#datagrid").datagrid("loadData", data.msg);
                } else {
                    $.messager.alert("提示","查询失败","error");
				}
            },
            error:function(data){
				$.messager.progress("close");
            }
        });
    }

    function priceFormatter(val,row) {
		return row.price+"/"+row.originalPrice;
	}

	function countFormatter(val,row) {
		return row.count+"/"+row.originalCount;
	}

	function totalFormatter(val,row) {
		return row.total+"/"+row.originalTotal;
	}
    function addDisableMatch(){
        var selectedRow = $("#datagrid").datagrid("getChecked");
        if(selectedRow!=null&&selectedRow.length>0){
            var ids = selectedRow.map(function (item,index) {
                return item.id;
            });
            var url = "/v2/suspectedHistoryMatchData/addDisableMatch",method="POST",params=JSON.stringify(ids);
            $.messager.confirm("提示","您确定追加禁用库吗?",function (r) {
                if(r){
                    $.ajax({
						url:config.url+url,
						type:method,
						data:params,
						dataType:"json",
						contentType:"application/json;charset=UTF-8",
						xhrFields:{withCredentials:true},
                        beforeSend:function () {
                            $.messager.progress({
                                title:"请稍等",
                                interval:50,
                                text:"数据加载中..."
                            });
                        },
                        complete:function () {
                            $.messager.progress("close");
                        },
						success:function (data) {
                            $.messager.progress("close");
                            if(data){
                                searchBy();
							}
                        },
						error:function (data) {

                        }
					})
                }
            })
        }else{
            $.messager.alert("提示","请选择相关记录","error");
            return false;
        }
    }

    function disabledTypeFormatter(val, row) {
        var res = "";
        switch (val) {
            case "OBLITERATE":
                res = "退货核销";
                break;
            case "SALESCOUNT":
                res = "销量异常";
                break;
			case "SALESPRICE":
                res = "销价异常";
                break;
            case "D2":
                res = "全品类禁用字";
                break;
            case "D3":
                res = "未识别品类";
                break;
            case "D4":
                res = "品类禁用字";
                break;
            case "D5":
                res = "禁用代换库";
                break;
            case "D6":
                res = "手动禁用";
                break;
            case "D7":
                res = "电商历史争议";
                break;
            case "D8":
                res = "渠道手工禁用";
                break;
            case "D9":
                res = "品类合并禁用";
                break;
            default:
                res = val;
        }
        return res;
    }

    function syncDisputeSku(){
        var param = getFormData(document.getElementById("ff"));
        param.reportType = window.parent.workMode.toUpperCase();
        $.messager.confirm("提示","您确定要执行同步争议sku代换库吗？",function (f) {
            if(f){
                $.ajax({
                    url:config.parseUrl+"/sales-detail/dispute-sku",
                    type:"post",
                    dataType:"json",
                    data:JSON.stringify(transfer(param)),
                    contentType:"application/json;charset=UTF-8",
                    // xhrFields:{withCredentials:true},
                    headers: {'Authorization': sessionStorage.getItem('Authorization')},
                    beforeSend:function () {
                        $.messager.progress({
                            title:"请稍等",
                            interval:50,
                            text:"操作进行中..."
                        });
                    },
                    complete:function () {
                        $.messager.progress("close");
                    },
                    success:function (data) {
                        $.messager.progress("close");
                        if (data.code == 0) {
                            $.messager.alert("提示",data.msg, "info");
                            return;
                        }
                        $.messager.alert("提示",data.msg, "error");
                    },
                    error:function (data) {

                    }
                });
            }
        });
	}

    $("#disableType").combobox({
        onChange:function () {
            var value = $("#disableType").combobox("getValue");
            if (value && value != "") {
                $("#entityStatus").switchbutton("uncheck")
            }
        }
    });
    $("#ff").keydown(function (event) {
        var e = event || window.event;
        var keyCode = e.keyCode || e.which;
        if(keyCode=="13"){
            searchBy();
        }
    });
</script>
</html>